/*********************/
/** SenseRFID.java */
/*********************/
package atag.apps.mainApp;

import atag.runtime.DataItem;
import atag.runtime.DataPool;
import atag.runtime.NodeInfo;
import atag.runtime.sensors.RFIDSensor;

public class SenseRFID implements Runnable {

	private DataPool m_dataPool;

	private NodeInfo m_myState;

        RFIDSensor rfidSensor;
        
	/** Creates a new instance of SenseRFID */
	public SenseRFID(DataPool dp, NodeInfo myconfig) {
		m_dataPool = dp;
		m_myState = myconfig;
	}

	public synchronized void run() {
	try {
			rfidSensor = new RFIDSensor("ACS ACR122U PICC Interface 0");
			this.m_myState
					.debugPrint("[SenseRFID] RFIDSensor CS ACR122 0 found");
		} catch (Exception ex) {
			ex.printStackTrace();
		}	
	while (true) {
			try {
				String UID = rfidSensor.getUID();
				RFID m_RFID = new RFID();
				m_RFID.setID(this.m_myState.getMyId());
				m_RFID.setRFID(UID);                           
				m_dataPool.putData(new DataItem(IDConstants.D_RFID,
						IDConstants.T_SENSERFID, m_RFID));
				this.m_myState.debugPrint("[SenseRFID] Got a ID: "
						+ this.m_myState.getMyId() + " RFID is: "
						+ m_RFID.getRFID());

			} catch (Exception ex) {
				ex.printStackTrace();
			}
		}


	}
}
